package com.mama100.rpc.mdp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mama100.common.finagle.FinagleClientRegister;
import com.mama100.rpc.mdp.thrift.*;

public class MdpRpcFactory {

    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    private CustBrandService.ServiceIface custBrandService;

    private CustTerminalService.ServiceIface custTerminalService;

    private CustPointService.ServiceIface custPointService;

    private OrderReportService.ServiceIface orderReportService;

    private CustTerminalBelongService.ServiceIface custTerminalBelongService;

    private TerminalCommissionService.ServiceIface terminalCommissionService;

    private FinagleClientRegister register;

    public synchronized CustBrandService.ServiceIface getCustBrandService() {
        if (custBrandService == null)
            try {
                custBrandService = (CustBrandService.ServiceIface) register.getClientService("custBrandService",
                        CustBrandService.class.getName());
            } catch (Exception ex) {
                logger.error("register custBrandService error", ex);
            }
        return custBrandService;
    }

    public synchronized CustTerminalService.ServiceIface getCustTerminalService() {
        if (custTerminalService == null)
            try {
                custTerminalService = (CustTerminalService.ServiceIface) register.getClientService("custTerminalService",
                        CustTerminalService.class.getName());
            } catch (Exception ex) {
                logger.error("register custTerminalService error", ex);
            }
        return custTerminalService;
    }

    public synchronized CustPointService.ServiceIface getCustPointService() {
        if (custPointService == null)
            try {
                custPointService = (CustPointService.ServiceIface) register.getClientService("custPointService",
                        CustPointService.class.getName());
            } catch (Exception ex) {
                logger.error("register custPointService error", ex);
            }
        return custPointService;
    }

    public synchronized OrderReportService.ServiceIface getOrderReportService() {
        if (orderReportService == null)
            try {
                orderReportService = (OrderReportService.ServiceIface) register.getClientService("orderReportService",
                        OrderReportService.class.getName());
            } catch (Exception ex) {
                logger.error("register orderReportService error", ex);
            }
        return orderReportService;
    }

    public synchronized CustTerminalBelongService.ServiceIface getCustTerminalBelongService() {
        if (custTerminalBelongService == null)
            try {
                custTerminalBelongService = (CustTerminalBelongService.ServiceIface) register.getClientService("custTerminalBelongService",
                        CustTerminalBelongService.class.getName());
            } catch (Exception ex) {
                logger.error("register custTerminalBelongService error", ex);
            }
        return custTerminalBelongService;
    }

    public synchronized TerminalCommissionService.ServiceIface getTerminalCommissionService() {
        if (terminalCommissionService == null)
            try {
                terminalCommissionService = (TerminalCommissionService.ServiceIface) register.getClientService("terminalCommissionService",
                        TerminalCommissionService.class.getName());
            } catch (Exception ex) {
                logger.error("register terminalCommissionService error", ex);
            }
        return terminalCommissionService;
    }

    public void setFinagleClientRegister(FinagleClientRegister value) {
        this.register = value;
    }
}